<!--
 * @Author: your name
 * @Date: 2022-03-14 23:30:25
 * @LastEditTime: 2022-03-20 10:11:56
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \算法测试\day0906\类型判断.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        console.log(typeof ''); //'string'
        console.log(typeof 123);//'number'
        console.log(typeof true);//'boolean'
        console.log(typeof undefined);//'undefined'
        console.log(typeof null);//'object'
        console.log(typeof function () { });//'function'
        console.log(typeof [1, 2, 3]);//'object'
        console.log(typeof { a: 1, b: 2 });//'object'
        console.log(typeof Symbol());//'symbol'
        console.log(typeof NaN);//'number'

        console.log(Object.prototype.toString.call(999));// "[object Number]"
        console.log(Object.prototype.toString.call('')); // "[object String]"
        console.log(Object.prototype.toString.call(Symbol())); // "[object Symbol]"
        console.log(Object.prototype.toString.call(42n)); // "[object BigInt]"
        console.log(Object.prototype.toString.call(null)); // "[object Null]"
        console.log(Object.prototype.toString.call(undefined)); // "[object Undefined]"
        console.log(Object.prototype.toString.call(true)); // "[object Boolean]
        console.log(Object.prototype.toString.call(NaN)); //"[object Number]"
        console.log(Object.prototype.toString.call([1,2,3])); //"[object Array]"
        console.log(Object.prototype.toString.call(function () {})); //"[object Function]"

        /*
        obj instanceof Object ，可以左边放你要判断的内容，右边放类型来进行JS类型判断，只能用来判断复杂数据类型,
        因为instanceof 是用于检测构造函数（右边）的 prototype 属性是否出现在 某个实例对象（左边）的原型链上。
        */
        console.log([1, 2] instanceof Array);   // true
        console.log((function () { }) instanceof Function); // true
        console.log(({ a: 1 }) instanceof Object); // true
        console.log((new Date) instanceof Date); // true
        console.log((new Date) instanceof Object); // true

        let arr = [];
        arr[6] = 1;
        console.log(arr,arr[2]); //稀疏数组 undefined
        console.log(new Array(3,2));
    </script>
</body>

</html>